import { createReducer } from '../utils/index'
import { 
	FETCH_ADDRESS_SUCC,
	FETCH_ADDRESS_FAIL,
	ADD_ADDRESS_SUCC,
	ADD_ADDRESS_FAIL,
	DEL_ADDRESS_SUCC,
	DEL_ADDRESS_FAIL,
	EDIT_ADDRESS_SUCC,
	EDIT_ADDRESS_FAIL,
	SET_DEFAULT_ADD_SUCC,
	SET_DEFAULT_ADD_FAIL, 
} from '../contants/address'

const initialState = {
	addressData: [],
	isFetched: null,
	isAdded: null,
	isDeled: null,
	isEdited: null,
	isSeted: null,
}


export default createReducer(initialState, {
	[FETCH_ADDRESS_SUCC]: (state, payload) => {
        return Object.assign({}, state, {
            'isFetched': true,
            'addressData': payload.data
        })
    },

    [FETCH_ADDRESS_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'isFetched': false,
            'addressData': []
        })
    },

    [ADD_ADDRESS_SUCC]: (state, payload) => {
        return Object.assign({}, state, {
            'isAdded': true
        })
    },

    [ADD_ADDRESS_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'isAdded': false
        })
    },

    [DEL_ADDRESS_SUCC]: (state, payload) => {
        return Object.assign({}, state, {
            'isDeled': true
        })
    },

    [DEL_ADDRESS_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'isDeled': false
        })
    },

    [EDIT_ADDRESS_SUCC]: (state, payload) => {
        return Object.assign({}, state, {
            'isEdited': true
        })
    },

    [EDIT_ADDRESS_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'isEdited': false
        })
    },

    [SET_DEFAULT_ADD_SUCC]: (state, payload) => {
        return Object.assign({}, state, {
            'isSeted': true
        })
    },

    [SET_DEFAULT_ADD_FAIL]: (state, payload) => {
        return Object.assign({}, state, {
            'isSeted': false
        })
    },
})
